home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Classes / 2.0_GraphView / Examples / Logger / Logger.m < prev    next >
Encoding:
Text File  |  1992-08-10  |  3.0 KB  |  156 lines

  1. /* Generated by Interface Builder */
  2.  
  3. #import "Logger.h"
  4. #import "GraphView.h"
  5. #import <appkit/Text.h>
  6. #import <appkit/ScrollView.h>
  7. #import <appkit/Control.h>
  8. #import <NXCType.h>
  9. #import <math.h>
  10. #import <dpsclient/psops.h>
  11. #import <dpsclient/wraps.h>
  12. #import <stdlib.h>
  13. #import <string.h>
  14.  
  15. #define MAXNUMLENGTH 50
  16.  
  17. @interface Logger (Private)
  18. -registerData; // opens a stream from text and parse into NXDPoints.
  19. @end
  20.  
  21. extern int getSeparator(NXStream *stream);
  22. extern double getNumber(NXStream *stream);
  23.  
  24. @implementation Logger (Private)
  25. -registerData
  26. {
  27.     int        c, sign, retval;
  28.     double    aNum;
  29.     NXDPoint    aPoint;
  30.     NXStream    *stream;
  31.     BOOL    processedLine = NO, gotFirst = NO, gotSecond = NO; 
  32.     stream=[theText stream];
  33.     NXSeek(stream, 0, NX_FROMSTART);
  34.     while ((c = NXGetc(stream)) != EOF)
  35.     {
  36.         sign = 1;
  37.     retval = getSeparator(stream);
  38.         if (retval == 1)
  39.     {
  40.         c = NXGetc(stream);
  41.     }
  42.     else if (retval == -1)
  43.         {
  44.             break;
  45.         }
  46.     
  47.     if (!NXIsDigit(c))
  48.     {
  49.         if ((c =='-') && NXIsDigit(c = NXGetc(stream)))
  50.         {
  51.             sign = -1;
  52.         }
  53.         else
  54.         {
  55.             while ((c!='\n') && (c!= EOF))
  56.             {
  57.                 c = NXGetc(stream);
  58.                 processedLine = YES;
  59.             }
  60.         }
  61.     }
  62.     
  63.     if (c == EOF) break;
  64.     else if (processedLine)
  65.     {
  66.         processedLine = NO;
  67.         continue;
  68.     }    
  69.     
  70.     aNum = getNumber(stream);
  71.     
  72.     if (!gotFirst)
  73.     {
  74.         aPoint.x = sign * aNum;
  75.         gotFirst = YES;
  76.     }
  77.     else if (!gotSecond)
  78.     {
  79.         aPoint.y = sign * aNum;
  80.         [thePlotView addThePoint:aPoint];
  81.             gotFirst = gotSecond = NO;
  82.     }
  83.     }
  84.     return self;
  85.  
  86. }
  87. int getSeparator(NXStream *stream)
  88. {
  89.     int    c, firstChar;
  90.     
  91.     NXUngetc(stream);
  92.     c = firstChar = NXGetc(stream);
  93.     while (NXIsSpace(c) || (c == ',') || (c == '+'))
  94.         c = NXGetc(stream);
  95.     
  96.     if (c == firstChar) 
  97.         return 0;
  98.     else if (c == EOF)
  99.         return -1;
  100.     NXUngetc(stream);
  101.     return 1;        
  102. }
  103. double getNumber(NXStream *stream)
  104. {
  105.     int c, i=0;
  106.     char *end;
  107.     char temp[MAXNUMLENGTH];
  108.     
  109.     NXUngetc(stream);
  110.     c=NXGetc(stream);
  111.     while ((NXIsDigit(c) || (c == '.')) && (c != '\n') && (c != EOF))
  112.     {
  113.         temp[i++] = c;
  114.         c = NXGetc(stream);
  115.     }
  116.     NXUngetc(stream);
  117.     temp[i] = 0;    
  118.     return (strtod(temp,&end));
  119. }                            
  120. @end
  121. @implementation Logger
  122. - appDidInit:sender
  123. {
  124. [[[thePlotView manualXMin:0.0] manualXMax:100.0] setXMajorTickWidthTo:20.0];
  125. [[[thePlotView manualYMin:-1.0] manualYMax:1.0] setYMajorTickWidthTo:0.2];
  126. [thePlotView setCurrentPenColorToRGBColor:0:0:0];
  127. [thePlotView setPointRadiusTo:0.01];
  128. theText=[theTextView docView];
  129. autoX=NO;
  130. autoY=NO;
  131. return self;
  132. }
  133.  
  134. -clear:sender
  135. {
  136. char buffer[100];
  137. sprintf(buffer,"");
  138. [theText selectAll:self];
  139. [theText replaceSel:buffer];
  140. [thePlotView clearDataInfo:self];
  141. return self;
  142. }
  143. - plot:sender
  144. {
  145.    [thePlotView clearDataInfo:self];
  146.    if  ([autoX intValue]) [thePlotView setXAutoscale:NO]; else [thePlotView setXAutoscale:YES];
  147.     if  ([autoY intValue]) [thePlotView setYAutoscale:NO]; else [thePlotView setYAutoscale:YES];
  148.    if([connected intValue]) 
  149.      [thePlotView setCurrentPenStyleTo:SLINE]; 
  150.      else [thePlotView setCurrentPenStyleTo:CIRCLE];
  151.    [self registerData];    
  152.     return self;
  153. }
  154.  
  155. @end
  156.